
import tushare as ts

from x01_stock.xx_util.DBUtil import SqlHelper

ts.set_token('2b5ccf8aa515d2c654cef2598e2f85ef8ff7b88fc5047a2c1ebc0296')
pro = ts.pro_api()
# 获取股票列表
# df = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')
# print(df.head())


df1 = pro.daily(ts_code='000040.SZ', start_date='20240701', end_date='20240703')
print(df1)
# 每一列的操作方式
# for col in df1.columns:  # 遍历DataFrame中的每一列
#     print(f"Column Name: {col}")
#     # 把数字中的 "," 替换掉（删除）
#     print(df1[col])
# 每一行的数据
sql = f"INSERT INTO ts_stock_daily (ts_code, trade_date, open_today, high, low, close_today, pre_close, price_change,  pct_chg,vol, amount) VALUES (%s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s)"  # SQL插入语句

for row in df1.itertuples(index=False):  # 遍历DataFrame中的每一行
    print(row)
    # SqlHelper.get_instance().execute_curd(sql, row)
    print("正在插入数据:", row)  # 输出正在插入的数据

